package cn.wolfcode.car.business.web.controller;

import cn.wolfcode.car.base.service.IUserService;
import cn.wolfcode.car.business.domain.Employee;
import cn.wolfcode.car.business.query.EmployeeQuery;
import cn.wolfcode.car.business.service.IBpmnInfoService;
import cn.wolfcode.car.business.service.IDepartmentService;
import cn.wolfcode.car.business.service.IEmployeeService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/business/employee")
public class EmployeeController {

    private static final String prefix = "business/employee/";

    @Resource
    private IEmployeeService employeeService;
    @Resource
    private IDepartmentService departmentService;

    @RequiresPermissions("business:employee:view")
    @RequestMapping("/listPage")
    public String listPage() {
        return prefix + "list";
    }

    @RequiresPermissions("business:employee:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<Employee> query(EmployeeQuery qo, Model model) {
        model.addAttribute("dept", departmentService.selectAll());
        return employeeService.query(qo);
    }

    @RequiresPermissions("business:employee:add")
    @RequestMapping("/addPage")
    public String addPage() {
        return prefix + "add";
    }

    //新增
    @RequiresPermissions("business:employee:add")
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Employee employee) {
        employeeService.save(employee);
        return AjaxResult.success();
    }

    @RequiresPermissions("business:employee:edit")
    @RequestMapping("/editPage")
    public String editPage(Long id, Model model) {
        model.addAttribute("employee", employeeService.get(id));
        return prefix + "edit";
    }

    //修改
    @RequiresPermissions("business:employee:edit")
    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Employee employee) {
        employeeService.update(employee);
        return AjaxResult.success();
    }

    @RequiresPermissions("business:employee:selectDept")
    @RequestMapping("/selectDept")
    public String selectDept(Long deptId, Model model) {
        model.addAttribute("dept", departmentService.get(deptId));
        return prefix + "dept";
    }

    //删除
    @RequiresPermissions("business:employee:remove")
    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long ids) {
        employeeService.deleteById(ids);
        return AjaxResult.success();
    }
}

